<template>
  <a-card class="card-wrapper" :loading="loading" title="员工业务量">
    <a-table
      size="small"
      :columns="columns"
      :data-source="tableData"
      :pagination="false"
      :loading="loading"
      :scroll="{ y: '100%' }"
      row-key="employeeId"
    />
    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        show-less-items
        :pageSizeOptions="[4, ...PAGE_SIZE_OPTIONS]"
        :defaultPageSize="params.pageSize"
        v-model:current="params.pageNum"
        v-model:pageSize="params.pageSize"
        :total="total"
        @change="fetchData"
        @showSizeChange="fetchData"
        :show-total="showTableTotal"
      />
    </div>
  </a-card>
</template>
<script setup>
  import { ref, onMounted, reactive } from 'vue';
  import { smartSentry } from '/@/lib/smart-sentry';
  import { PAGE_SIZE_OPTIONS, showTableTotal } from '/@/constants/common-const';

  const loading = ref(true);
  const total = ref(0);
  const tableData = ref([]);
  const params = reactive({
    pageNum: 1,
    pageSize: 4,
  });
  const columns = ref([
    {
      title: '员工姓名',
      dataIndex: 'name',
    },
    {
      title: '已完成',
      dataIndex: 'completeCnt',
    },
    {
      title: '超期',
      dataIndex: 'delayCnt',
    },
    {
      title: '访谈中',
      dataIndex: 'doingCnt',
    },
    {
      title: '异常',
      dataIndex: 'exceptionCnt',
    },
    {
      title: '总单量',
      dataIndex: 'totalCnt',
    },
  ]);

  const fetchData = async () => {
    try {
      loading.value = true;
      const res ={
        "code": 0,
        "level": null,
        "msg": "success",
        "ok": true,
        "data": {
          "pageNum": 1,
          "pageSize": 4,
          "total": 15,
          "pages": 4,
          "list": [
            {
              "employeeId": null,
              "name": "赵韵",
              "completeCnt": 0,
              "delayCnt": 0,
              "doingCnt": 0,
              "exceptionCnt": 0,
              "totalCnt": 0,
              "loginName": "zhaoy163",
              "patformEmployeeVO": null,
              "tenantEmployeeVO": null
            },
            {
              "employeeId": null,
              "name": "傅浚吉",
              "completeCnt": 0,
              "delayCnt": 0,
              "doingCnt": 0,
              "exceptionCnt": 0,
              "totalCnt": 0,
              "loginName": "fujj24",
              "patformEmployeeVO": null,
              "tenantEmployeeVO": null
            },
            {
              "employeeId": null,
              "name": "高莹",
              "completeCnt": 1315,
              "delayCnt": 0,
              "doingCnt": 0,
              "exceptionCnt": 0,
              "totalCnt": 1315,
              "loginName": "gaoyingwy",
              "patformEmployeeVO": null,
              "tenantEmployeeVO": null
            },
            {
              "employeeId": null,
              "name": "王迪",
              "completeCnt": 0,
              "delayCnt": 0,
              "doingCnt": 0,
              "exceptionCnt": 0,
              "totalCnt": 0,
              "loginName": "wangd169",
              "patformEmployeeVO": null,
              "tenantEmployeeVO": null
            }
          ],
          "emptyFlag": null
        }
      }
      if (res.code === 0) {
        tableData.value = res.data.list || [];
        total.value = res.data.total;
      }
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      loading.value = false;
    }
  };

  onMounted(() => {
    fetchData();
  });
</script>
<style lang="less" scoped>
  .card-wrapper {
    :deep(.ant-card-body) {
      padding: 1px 0 4px 0;
    }
  }
</style>
